class ListsController < ApplicationController
  
  resource(:lists) do
    
    respond_to :html, :xml
  
    collection do
      GET { @lists = List.find(:all) }
    end
  
    action "new" do
      GET(:html) do
        @list = List.new
      end
    end

    member ":name" do
      
      find { List.find_by_name(params[:name]) }
    
      action "edit" do
        GET(:html)
      end
    
      GET { @items = @list.items.find(:all) }

      PUT(:if => :found?) do |f|
        @list.attributes = params[:list]
        if @list.save
          redirect_to list_url(@list)
        else
          render :action => "edit", :status => :bad_request
        end
      end
    
      PUT(:unless => :found?) do
        @list = List.new(:name => params[:name])
        @list.attributes = params[:list]
        if @list.save
          redirect_to list_url(@list)
        else
          render :action => "new", :status => :bad_request
        end
      end
    
      DELETE do
        @list.destroy if @list
        redirect_to lists_url
      end
    
    end
  end

end